package com.easy.user.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.easy.common.bean.SysPermission;
import com.easy.common.service.IPermissionService;
import com.easy.common.util.ResultData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("permission")
@RestController
@CrossOrigin
public class PermissionController {
    @Autowired
    IPermissionService permissionService;
    @GetMapping("list")
    public ResultData getAllPermission(SysPermission permission){
        List<SysPermission> list= permissionService.getList(permission);
        return ResultData.success(list);
    }

    @GetMapping("page")
    public ResultData getByPage(Page page , SysPermission permission){
        System.out.println("permission/page");
        IPage<SysPermission> list= permissionService.getListByPage(page,permission);
        return ResultData.success(list);
    }
    @PostMapping("/")
    public ResultData addPermission(@RequestBody  SysPermission permission){
        SysPermission newpermission=permissionService.insert(permission);
        return ResultData.success(newpermission);
    }
    @DeleteMapping("/{id}")
    public ResultData deletePermission(Integer id){
        permissionService.delete(id);
        return ResultData.success();
    }
    @PutMapping("/")
    public ResultData editPermission(@RequestBody  SysPermission permission){
        SysPermission newPermission=permissionService.update(permission);
        return ResultData.success(newPermission);
    }

}
